# -*- coding: utf-8 -*-
# @Time  : 2021/8/2 下午10:51
# @Author : huangyuan
# @Project : algorithm
# @FileName: DateUtils.py
# @Description: 时间工具类

# 时间工具类
import time


# 计算方法执行的时间 - 装饰类
def calculate_fun_runtime(method_name="空函数"):
    def decode_fun(func):
        def wrapper(*args, **kwargs):
            start_time = time.time()
            time_unit = "s"
            value = func(*args, **kwargs)
            total_time = time.time() - start_time
            if 100.0 >= total_time > 0.001:
                total_time = total_time * 1000
                time_unit = "ms"
            if total_time <= 0.001:
                total_time = total_time * 1000000
                time_unit = "us"
            total_time = int(round(total_time))
            print(f'方法:{method_name}, 执行时间是:{total_time}{time_unit}')
            return value
        return wrapper
    return decode_fun
